Repository navigation
refactor(lsp): share GitHub-release and dotnet-tool install logic across downloaded servers - #161
Conversation
…oss downloaded servers github-release.ts holds the shared download logic: serverCacheDir, findCachedBinary, and downloadReleaseBinary. downloadReleaseBinary fetches the latest release and finds this platform's asset. It downloads into a temp dir and unzips or untars into the destination dir. It then checks the binary and makes it executable. terraform, texlab and lua now call it. lua still uses its staging dir and publishInstall. dotnet-tool.ts adds dotnetToolServer, which csharp and fsharp now build from. The cache dirs are unchanged. This clears the remaining duplication SonarCloud reports. New tests: a csharp-ls tool already in the cache is used, and texlab downloads its release.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request refactors the LSP server implementations by introducing shared helpers (dotnet-tool.ts and github-release.ts) to centralize the installation and spawning of .NET tools and GitHub release binaries, significantly reducing code duplication across several language servers. Unit tests have also been added to verify these auto-installation behaviors. Feedback on the changes highlights a high-severity issue in github-release.ts where unhandled network exceptions and a missing User-Agent header could cause failures during GitHub API calls, as well as a medium-severity issue in dotnet-tool.ts where unhandled exceptions during the dotnet tool installation process could lead to application instability.
SonarCloud S2612 flagged the 0o755 chmod in downloadReleaseBinary. The binary lives in the user's own cache dir and only that user runs it.
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryShares GitHub release downloads across Lua, Terraform, and Texlab, and .NET tool installation across C# and F#.
|
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Architecture diagram
sequenceDiagram
participant Server as Language Server (csharp/fsharp/lua/terraform/texlab)
participant Helper as Shared Install Helper<br/>(github-release.ts / dotnet-tool.ts)
participant FS as File System<br/>($HOME/.cache/dora/*)
participant GitHub as GitHub API<br/>(api.github.com)
participant Spawn as Spawned Process<br/>(dotnet/tar/LSP server)
Note over Server,Helper: Server activation flow (per language)
Server->>Helper: spawn(root) - request server binary
Helper->>FS: findCachedBinary(name, cacheDirs)
alt Binary found on PATH or cache
FS-->>Helper: binary path
Helper->>Spawn: spawn(bin, [], { cwd: root })
Spawn-->>Helper: process handle
Helper-->>Server: { process }
else Binary not cached
FS-->>Helper: null
alt dotnet tool server (csharp/fsharp)
Helper->>Spawn: check 'dotnet' on PATH
alt dotnet missing
Spawn-->>Helper: not found
Helper-->>Server: undefined (log warning)
else dotnet present
Helper->>Helper: check autoInstallDisabled(serverId)
alt auto-install disabled
Helper-->>Server: undefined
else auto-install enabled
Helper->>FS: mkdir(cacheDir)
Helper->>Spawn: dotnet tool install <tool> --tool-path <cache>
Spawn-->>Helper: exit code
alt install success
Helper->>FS: construct binary path
Helper->>Spawn: spawn(bin, [], { cwd: root })
Spawn-->>Helper: process handle
Helper-->>Server: { process }
else install failed
Helper-->>Server: undefined (log error)
end
end
end
else GitHub release server (lua/terraform/texlab)
Helper->>Helper: check autoInstallDisabled(serverId)
alt auto-install disabled
Helper-->>Server: undefined
else auto-install enabled
Helper->>GitHub: fetch /repos/{repo}/releases/latest
GitHub-->>Helper: release JSON
Helper->>Helper: find asset by platform (assetName)
alt asset found
Helper->>FS: create temp dir (os.tmpdir)
Helper->>GitHub: download asset to temp dir
GitHub-->>Helper: archive file
Helper->>Spawn: extract archive (tar -xzf or unzip)
Spawn-->>Helper: extraction result
alt extract success
Helper->>FS: verify binary exists
Helper->>FS: chmod binary (0o700, non-Windows)
alt lua (staged install)
Helper->>FS: stage binary in temp dir
Helper->>FS: publishInstall() - atomic move to cache
FS-->>Helper: success/failure
else terraform/texlab (direct install)
Helper->>FS: extract directly to cache dir
end
Helper->>FS: cleanup temp dir
Helper->>Spawn: spawn(bin, [], { cwd: root })
Spawn-->>Helper: process handle
Helper-->>Server: { process }
else extract failed
Helper->>FS: cleanup temp dir
Helper-->>Server: undefined (log error)
end
else asset not found
Helper-->>Server: undefined (log error)
end
end
end
end
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
- downloadReleaseBinary: the release lookup (fetch, JSON parse, asset name) now runs inside an error boundary, so offline or malformed responses log and return false - dotnet-tool: catch install errors; read stderr while waiting for exit - lua-ls: restore chmod on the published binary so a kept install that lost its execute bit runs again - test: terraform returns undefined when the release lookup fails
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the LSP server implementations by extracting shared logic for installing and spawning servers. It introduces dotnet-tool.ts for NuGet-based tools and github-release.ts for downloading and extracting binaries from GitHub releases, significantly reducing code duplication across csharp, fsharp, lua, terraform, and texlab servers. Unit tests have also been updated to cover these new installation flows. The review feedback highlights two key issues in github-release.ts: a potential deadlock and uncaught synchronous error when spawning the tar process, and a missing timeout on the GitHub API fetch request which could cause the process to hang indefinitely.
- bound the GitHub release-info request with a 30s AbortSignal timeout - extract tar archives with stdout ignored and stderr read while waiting for exit
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the LSP server implementations by centralizing the installation logic. It introduces dotnet-tool.ts for .NET tool installations and github-release.ts for downloading and extracting binaries from GitHub releases, simplifying csharp.ts, fsharp.ts, lua.ts, terraform.ts, and texlab.ts. Feedback on these changes includes ensuring the destination directory is created before extracting zip archives in github-release.ts to prevent clean-install failures, and removing a redundant fs.chmod call in lua.ts since permissions are already set during the download process.
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findingsRefactoring language-server downloads changes failure handling; install errors now return no server, potentially leaving affected projects without that language server. Shares GitHub-release download and dotnet-tool install logic across Lua, Terraform, Texlab, C#, and F# language servers, removing duplicated install code. The release-info fetch and JSON error that previously escaped the helper and made spawn throw is now handled, so failures are logged and return no server. No open issues found. ✅ 1 closed✅ Edge Case: Release-info fetch/JSON errors escape the helper and make spawn throw
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Approved For more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Important Your trial ends in 4 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more. Was this helpful? React with 👍 / 👎 | Gitar |



Summary
SonarCloud still reports duplication in the language servers that download a binary instead of installing from npm. csharp and fsharp had identical
dotnet tool installcode. lua, terraform and texlab each repeated the same steps: fetch the latest GitHub release, pick the asset, download, extract, check the binary, chmod. This follows #159, which shares the install logic for the npm-based servers. The two PRs touch different files and are independent.What changed
packages/lsp/src/server/github-release.tswithserverCacheDir(name),findCachedBinary(name, ...dirs)anddownloadReleaseBinary(spec, destDir, bin).findCachedBinarychecks PATH first, then the cache dirs. It skips an unset PATH instead of producing anundefined:entry.downloadReleaseBinaryfetchesreleases/latestand finds the platform asset throughspec.assetName(release). It downloads into a temp dir that it always removes, unzips.zipassets (extractZip) or runstar -xzfthrough Bun.spawn for everything else, then checksbinand chmods it 755. Any failure is logged and returns false.publishInstall, and downloads into the staging dir through the helper.packages/lsp/src/server/dotnet-tool.tswithdotnetToolServer({ id, tool, extensions, rootMarkers }). csharp.ts and fsharp.ts are now built from it.Scope
Covers the binary-download and dotnet-tool servers only. The npm-based servers are in #159. Cache dirs and the auto_install gate are unchanged.
Tradeoffs
downloadAndExtractfrom @pleaseai/binaries was not used. Its tar extraction goes throughexecSyncin a shell, and that shell looks uptaron PATH. A PATH without tar (as in the unit test) fails where the old Bun.spawn call worked. Possible follow-up: switch that helper to Bun.spawn.Blast radius
$HOME/.cache/dora/...keep working.spawn. Now they are logged andspawnreturns undefined.Verification
bun test packages/lsp/test/unit: 195 pass.bun run typecheckand eslint are clean.packages/lsp/test/unit/auto-install.test.ts: csharp-ls runs a tool that is already in the cache, and texlab downloads its release binary with a stubbed fetch. The existing lua download, cache, and gate-off tests still pass.Related issue
None.
Checklist
bun run test)bun run lint)BREAKING CHANGE:note is includedSummary by cubic
Shares GitHub-release download logic across Lua, Terraform, and Texlab, and .NET tool installation across C# and F#. This removes duplicated install code while preserving existing cache locations and auto-install behavior.
spawn. Release-info requests have a 30-second timeout.csharp-ls, installing Texlab from a release, and Terraform returning undefined on release lookup failure.Written for commit c9372e9. Summary will update on new commits.